﻿using Anke.SHManage.BLL;
using Anke.SHManage.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Anke.SHManage.Web.Areas.DM.Controllers
{
    public class DriverReportDMController : Controller
    {
        //
        // GET: /DM/DriverReportDM/

        public ActionResult DriverReportDMList()
        {
            return View();
        }


        //获取日报主表内容
        public ActionResult GetReportMainDM()
        {
            int rows = int.Parse(Request.Form["rows"]);
            int page = int.Parse(Request.Form["page"]);
            string zcenterCode = Convert.ToString(Request.Form["zcenterCode"]);
             string zstationCode = Convert.ToString(Request.Form["zstationCode"]);
             string zPlateNumber = Convert.ToString(Request.Form["zPlateNumber"]);
             DateTime zReportDateStart = Convert.ToDateTime(Request.Form["zReportDateStart"]);
             DateTime zReportDateEnd = Convert.ToDateTime(Request.Form["zReportDateEnd"]);
             string zAgentWorkID = Convert.ToString(Request.Form["zAgentWorkID"]);
             string zMoreKM = Convert.ToString(Request.Form["zMoreKM"]);


             int rowCounts = 0;


             var list = new DriverReportBLL().GetReportMainDM(rows, page, ref  rowCounts, zcenterCode, zstationCode
                 , zPlateNumber, zReportDateStart, zReportDateEnd, zAgentWorkID, zMoreKM);

            // 生成规定格式的 json字符串发回 给异步对象
            Model.EasyUIModel.DataGridModel dgModel = new Model.EasyUIModel.DataGridModel()
            {
                total = rowCounts,
                rows = list,
                footer = null
            };
            return Json(dgModel);

        }


        /// <summary>
        /// 修改下班路码，上班路码和公里数
        /// </summary>
        /// <returns></returns>

        [HttpPost]
        public ActionResult SaveDriverReportDM()
        {
            
           string sbOffDutyKM = Convert.ToString(Request.Form["sbOffDutyKM"]);//修改项的ID
             string sbOnDutyKM = Convert.ToString(Request.Form["sbOnDutyKM"]);//修改项的ID
             string sbDayKM = Convert.ToString(Request.Form["sbDayKM"]);//修改项的ID
             string sbID = Convert.ToString(Request.Form["sbID"]);//修改项的ID

            D_DriverReport rvinfo = new D_DriverReport();
        
                var guid = new Guid(sbID);
                rvinfo.ID = guid;
                rvinfo.OffDutyKM = int.Parse(sbOffDutyKM);
                rvinfo.OnDutyKM = int.Parse(sbOnDutyKM);
                rvinfo.DayKM = int.Parse(sbDayKM);
                int zbresults = new D_DriverReportBLL().Modify(rvinfo, "OffDutyKM", "OnDutyKM", "DayKM");
                if ( zbresults > 0)
                {
                    return this.JsonResult(Utility.E_JsonResult.OK, "添加信息成功！", null, null);
                }
                else
                {
                    return this.JsonResult(Utility.E_JsonResult.Error, "添加信息失败！", null, null);
                }
            }
    }
}
